#include "stdafx.h"

namespace cpputils
{

timer::timer()
	: Time(0), Timing(false)
{
}

double timer::time() const
{
	return double(Time + get_passed()) / CLOCKS_PER_SEC;
}

void timer::time(const double& Val)
{
	Time = clock_t(Val * CLOCKS_PER_SEC) - get_passed();
}

void timer::start()
{
	if (Timing) return;
	Timing = true;
	Start = clock();
}

void timer::stop()
{
	if (!Timing) return;
	Time += get_passed();
	Timing = false;
}

clock_t timer::get_passed() const
{
	if (Timing) return clock() - Start;
	return 0;
}

}
